import request from '@/utils/request'

/**
 * 获取组织架构数据
 */
export function getDepartments() {
  return request({
    url: '/company/department'
  })
}

/**
 * 根据id删除部门
 * @param {string} id 部门id
 * @returns Promise
 * RestFul 架构风格: 同一个url地址，不同的请求方法，执行不能的功能
 * POST /company/department 新增
 * PUT /company/department 修改
 * GET /company/department/1 查询
 * DELETE /company/department/1 删除
 */
export function delDepartments(id) {
  return request({
    url: `/company/department/${id}`,
    method: 'delete'
  })
}

/**
 *  新增部门接口
 */
export function addDepartments(data) {
  return request({
    url: '/company/department',
    method: 'post',
    data
  })
}

/**
 * 获取部门详情
 */
export function getDepartDetail(id) {
  return request({
    url: `/company/department/${id}`
  })
}

/**
 * 编辑部门
 */
export function updateDepartments(data) {
  return request({
    url: `/company/department/${data.id}`,
    method: 'put',
    data
  })
}
